/*
 * @Description:
 * @Author: maxyang
 * @Date: 2022-06-06 06:59:15
 * @LastEditTime: 2022-06-27 17:35:39
 * @LastEditors: liutq
 * @Reference:
 */
package admin

import (
	"time"

	"github.com/maxyang107/jinglan/common"
	"github.com/maxyang107/jinglan/model/goods"
	"github.com/maxyang107/jinglan/utils"
)

var (
	AdminGoodsService = &GoodsSer{}
)

type GoodsSer struct{}

func (g GoodsSer) AddGoods(query_ *common.Goods) error {
	gci := utils.GetChainInfoForGoods(query_.GoodsListImg)
	query_.Createtime = time.Now()
	query_.Updatetime = time.Now()

	if query_.GoodsCate != 3 {
		query_.Drawtime = time.Now().Format("2006-01-02 15:04:05")
	}
	return goods.AddGoods(query_, &gci)
}

func (g GoodsSer) ModifyGoods(query_ *common.Goods) error {
	query_.Updatetime = time.Now()

	if query_.Drawtime == "" {
		query_.Drawtime = time.Now().Format("2006-01-02 15:04:05")
	}
	return goods.ModifyGoods(query_)
}

func (g GoodsSer) GetGoodsList(query_ common.AdminGoodsList) goods.GoodsList {
	if query_.PerPage == 0 {
		query_.PerPage = 10
	}
	return goods.GetAdminGoodsList(query_)
}

func (g GoodsSer) GetGoodsDetail(goodsid uint) goods.GoodsTmp {
	return goods.GetAdminGoodsDetail(int(goodsid))
}

func (g GoodsSer) OpenDraw(goodsid uint, opennum uint) error {
	return goods.OpenDraw(goodsid, opennum)
}

func (g GoodsSer) GetVshopGoodsList(param_ common.AdminGoodsList) (*common.VShopgoods, error) {
	return common.GetVshopGoodsList(int(param_.Page), int(param_.PerPage))
}

func (g GoodsSer) GetDrawTotal(goodsid uint) uint {
	return goods.GetDrawTotal(goodsid)
}
